from paste.httpheaders import list_headers

import pyframe

from block_method import BlockMethod

class GetHttpHeaders(BlockMethod):

	def run(self):

		result = '<headers>'
		for header in list_headers(request = True):
			try:
				result += '<header name="%s" version="%s">%s</header>' % (header.name, header.version, header.parse())
			except Exception:
				result += '<header name="%s" version="%s">%s</header>' % (header.name, header.version, ";".join(header.values(pyframe.getEnviron())))

		return result + '</headers>'